package com.wu.webflux5.handler;

import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler;

import com.alibaba.fastjson.JSON;
import com.wu.webflux5.model.vo.R;

import reactor.core.publisher.Mono;

public class MyLogoutSuccessHandler implements ServerLogoutSuccessHandler{

	@Override
	public Mono<Void> onLogoutSuccess(WebFilterExchange exchange, Authentication authentication) {
		ServerHttpResponse response = exchange.getExchange().getResponse();
		response.setStatusCode(HttpStatus.OK);
		HttpHeaders headers = response.getHeaders();
		headers.add("Content-Type", "application/json;charset=UTF-8");
		String jsonString = JSON.toJSONString(R.ok("退出成功"));
		DataBuffer res = response.bufferFactory().wrap(jsonString.getBytes());
		return response.writeWith(Mono.just(res));
	}

}
